package com.wyw.function.learning.demo1;

import com.wyw.function.learning.common.Person;

import java.util.Arrays;
import java.util.Random;

/**
 * @Title   静态方法的引用
 * @Description
 * @Author Mr Wu yewen.wu.china@gmail.com
 * Update History:
 * Author        Time            Content
 */
public class StaticMethodClient {
    public static void main(String[] args) {
        Random random = new Random();
        Person[] people = new Person[30];

        for (int i = 0; i < 30; i++) {
            Person person = new Person();
            person.setName(String.valueOf(i));
            person.setAge(random.nextInt(40));
            people[i] = person;
        }

//        Arrays.sort(people, new PersonAgeComparator());
        // 可以使用Lambda方式
//        Arrays.sort(people, (a, b) -> {
//            return a.getAge().compareTo(b.getAge());
//        });

        // 使用静态方法的构造器
//        Arrays.sort(people, (a, b) -> Person.compareByAge(a, b));
        Arrays.sort(people, Person::compareByAge);

        for (Person person: people) {
            System.out.println(person);
        }
    }
}
